<?php

namespace Acme\DemoBundle\Repository;

use Doctrine\ORM\EntityRepository;

class NhanvienthiduaRepository extends EntityRepository
{
	public function getByCondition($nhanvienid, $nam)	{
		$qb = $this->createQueryBuilder('p')
		->where('p.nhanvienid = :nhanvienid')
		->andWhere('p.nam = :nam')
		->setParameter('nhanvienid', $nhanvienid)
		->setParameter('nam', $nam)
		;
		$result = $qb->getQuery()->getResult();
		if(\Count($result)>0){
			return $result[0];
		}
		return null;
	}

	public function saveNhanvienthidua($lstThiDua) {
		$em = $this->getEntityManager();
		$em->getConnection()->beginTransaction(); // suspend auto-commit
		try {
			foreach ($lstThiDua as $thidua) {
				$em->persist($thidua);
				$em->flush();
			}
			$em->getConnection()->commit();
		} catch (Exception $e) {
			$em->getConnection()->rollback();
			$em->close();
			throw $e;
		}

	}
}